<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.Vector,com.ejoysoft.wlanyz.system.Maintainer,com.ejoysoft.common.Constants,com.ejoysoft.wlanyz.system.SysUserUnit,com.ejoysoft.common.exception.NoRightException" %>
<%@ include file="../include/jsp/head.jsp"%>
<%@page import="sun.reflect.generics.tree.IntSignature"%>
<%@page import="com.ejoysoft.common.Format"%>
<%
if(!globa.userSession.hasRight("70015"))
      throw new NoRightException("用户不具备操作该功能模块的权限，请与系统管理员联系！");
 
    //初始化
   Maintainer  user0=null;
   Maintainer  obj=new Maintainer (globa);
    //查询条件
   String strMainName= ParamUtil.getString(request,"strMainName","");
   String strMainMobile=ParamUtil.getString(request,"strMainMobile","");
   
    	//当前页
	int intCurPage= Integer.parseInt(ParamUtil.getString(request,"strCurPage","1"));
	String tWhere=" WHERE 1=1";
	if(!strMainName.equals("")){
     tWhere += " and strMainName LIKE '%"+ strMainName +"%'";
    }
	if (!strMainMobile.equals("")) {
		tWhere += " and strMainMobile LIKE '%" + strMainMobile + "%'";
	}
	
	String checked1 =  ParamUtil.getString(request,"checkedFlag","all"); 
	if(checked1.equals("checked")){
	  tWhere += " and checkedLocation is not null and checkedLocation <>' ' ";
	}
	else if(checked1.equals("unchecked")){
	  tWhere += " and checkedLocation is null or checkedLocation =' '";
	}
	tWhere += " "; 

	//记录总数
	int intAllCount=obj.getCount(tWhere);	

	//每页记录数
	String strPageSize = ParamUtil.getString(request,"strPageSize","10");
    int intPageSize;
    if(strPageSize.equals("所有"))intPageSize = intAllCount;
      else  intPageSize = Integer.parseInt(strPageSize);
	//共有页数
 	int intPageCount=(intAllCount-1)/intPageSize+1;
	// 循环显示一页内的记录 开始序号
	int intStartNum=(intCurPage-1)*intPageSize+1;
	//结束序号
	int intEndNum=intCurPage*intPageSize;   
	//获取到当前页面的记录集
	Vector<Maintainer > vctObj=obj.list(tWhere,intStartNum,intPageSize);
	//获取当前页的记录条数
	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
	
	String exportContent = ParamUtil.getString(request,"exportContent","");
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list(tWhere,0,0);
		}
   	   	StringBuffer sb = new StringBuffer();
	    sb.append("姓名,性别,归属地,手机号,身份证,电话号码,职位,操作人,操作时间\n");
	    
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       String strSb = vctObj.get(i).getStrMainName().replace("\n","") == null? "," :vctObj.get(i).getStrMainName().replace("\n","")+ ",";
		       strSb += (vctObj.get(i).getStrMainSex()== null || vctObj.get(i).getStrMainSex().equals(""))? ",":vctObj.get(i).getStrMainSex().replace("\n","")+ ",";
		       strSb += (vctObj.get(i).getStrMainAddr()== null || vctObj.get(i).getStrMainAddr().equals(""))? ",":vctObj.get(i).getStrMainAddr().replace("\n","")+ ",";
		      strSb += (vctObj.get(i).getStrMainMobile()== null || vctObj.get(i).getStrMainMobile().equals(""))? ",":vctObj.get(i).getStrMainMobile().replace("\n","")+ ",";
		      strSb += (vctObj.get(i).getStrMainIdnum()== null || vctObj.get(i).getStrMainIdnum().equals(""))? ",":vctObj.get(i).getStrMainIdnum().replace("\n","")+ ",";
		      strSb += (vctObj.get(i).getStrMainTel()== null || vctObj.get(i).getStrMainTel().equals(""))? ",":vctObj.get(i).getStrMainTel().replace("\n","")+ ",";
		      strSb += (vctObj.get(i).getStrMainPosition()== null || vctObj.get(i).getStrMainPosition().equals(""))? ",":vctObj.get(i).getStrMainPosition().replace("\n","")+ ",";
		       strSb += (vctObj.get(i).getStrCreator()== null || vctObj.get(i).getStrCreator().equals(""))? ",":vctObj.get(i).getStrCreator().replace("\n","")+ ",";
		       strSb += (vctObj.get(i).getDtCreatDate()== null || vctObj.get(i).getDtCreatDate().equals(""))? ",":vctObj.get(i).getDtCreatDate().replace("\n","")+ ",\n";
		        sb.append(strSb);
		    }
	    } 
	    String strFileName = "代维人员信息核查表.csv";//自定义csv文件的文件名
	    response.setContentType("APPLICATION/*");
	    response.setHeader( "Content-Disposition", "attachment;filename="  + new String( strFileName.getBytes("gbk"), "ISO8859-1" ));
	    out.clearBuffer(); 
	    out = pageContext.pushBody();
	    ServletOutputStream output = response.getOutputStream();
	    output.write(sb.toString().getBytes());
	    globa.closeCon();
	    
%>
<%@ include file="../include/jsp/footer.jsp"%>
